package game.module.item.dao;

import game.module.item.beans.Goodmodel;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.ResultSetExtractor;
import org.springframework.stereotype.Component;

@Component
public class GoodModelDao {

	@Autowired
	private JdbcTemplate jdbcTemplate;

	public List<Goodmodel> getAll() {
		return jdbcTemplate.query("select * from snake_gamedata.t_goodmodel", new ResultSetExtractor<List<Goodmodel>>() {
			@Override
			public List<Goodmodel> extractData(ResultSet rs) throws SQLException, DataAccessException {
				List<Goodmodel> modelList = new ArrayList<Goodmodel>();
				while (rs.next()) {
					Goodmodel model = new Goodmodel();
					model.setId(rs.getInt("f_id"));
					model.setName(rs.getString("f_name"));
					model.setDesc(rs.getString("f_desc"));
					model.setUseDesc(rs.getString("f_use_desc"));
					model.setUseDescI18n(rs.getString("f_use_desc_i18n"));
					model.setPopsinger(rs.getInt("f_popsinger"));
					model.setKind(rs.getShort("f_kind"));
					model.setBinding(rs.getByte("f_binding"));
					model.setDiscard(rs.getBoolean("f_discard"));
					model.setDrugType(rs.getInt("f_drug_type"));
					model.setDrugBuffId(rs.getInt("f_drug_buff_id"));
					model.setDrugValue(rs.getInt("f_drug_value"));
					model.setLimitGrade(rs.getInt("f_limit_grade"));
					model.setRepeat(rs.getInt("f_repeat"));
					modelList.add(model);
				}
				return modelList;
			}
		});
	}

}
